package com.yuqih.common.service.view.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuqih.common.service.view.IViewConverter;
import com.yuqih.common.service.view.IViewService;

@Service
public class ViewServiceConverter implements IViewConverter {

	@Autowired
	private IViewService viewService;

	@Override
	public String alias() {
		return Alias_View_Service;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Object convert(Object source, Context context) {
		if (source == null) {
			return null;
		}

		if (context.isList()) {
			return viewService.buildList(context.getType(), context.getParam(), (List) source);
		} else {
			return viewService.build((Class) context.getType(), context.getParam(), source);
		}

	}

}
